# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Bartłomiej Piotrowski <bpiotrowski@archlinux.org>
# Contributor: kevin <kevin@archlinux.org>
# Contributor: Eric Johnson <eric@coding-zone.com>

pkgname=perl-dbd-mysql
pkgver=4.048
pkgrel=1
pkgdesc='Perl/CPAN DBD::mysql module for interacting with MySQL via DBD'
arch=('x86_64')
license=('GPL' 'PerlArtistic')
url="http://search.cpan.org/dist/DBD-mysql/"
depends=('libmariadbclient' 'perl-dbi')
makedepends=('perl-devel-checklib')
checkdepends=('mariadb' 'perl-test-deep')
options=('!emptydirs')
source=(http://search.cpan.org/CPAN/authors/id/M/MI/MICHIELB/DBD-mysql-${pkgver}.tar.gz
        mariadb-fix.patch)
sha512sums=('30a3c9d38f9331a20e2c4c65bfbb547443d888afb35c7fd42c8220797d8ecf79640d95736a6fb3ebc4df71c25366e93c19ba37b258aa17e7c5623a1404607e62'
            '12a54c184240babe3d35391122dbdd37de34f673cf411ddaeb89d1d2eb4e5edf3c2a3b3bd01e79da8f11b90a8b77102f52505683eea293ff4b0b764ee427bcc3')

prepare() {
  cd DBD-mysql-$pkgver
  # https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=231271
  patch -p0 -i ../mariadb-fix.patch
}

build() {
  cd DBD-mysql-$pkgver
  perl Makefile.PL INSTALLDIRS=vendor --testsocket=/tmp/socket.mysql
  make
}

check() {
  cd DBD-mysql-$pkgver
  mkdir -p /tmp/mysql_test
  mysql_install_db \
     --basedir=/usr \
     --datadir=/tmp/mysql_test
  mysqld -P 17999 \
     --socket=/tmp/socket.mysql \
     --datadir=/tmp/mysql_test &
  sleep 10
  DAEMON_PORT=$!
  make test
  kill -9 $DAEMON_PORT
}

package() {
  cd DBD-mysql-$pkgver
  make install DESTDIR="$pkgdir"
}
